home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / madcow1a / madcowte.frm (.txt) < prev    next >
Visual Basic Form  |  1999-09-30  |  7KB  |  181 lines

  1. VERSION 5.00
  2. Begin VB.Form frmmain 
  3.    BackColor       =   &H80000000&
  4.    BorderStyle     =   3  'Fixed Dialog
  5.    ClientHeight    =   3480
  6.    ClientLeft      =   3045
  7.    ClientTop       =   3240
  8.    ClientWidth     =   4590
  9.    ClipControls    =   0   'False
  10.    ControlBox      =   0   'False
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   3480
  15.    ScaleWidth      =   4590
  16.    ShowInTaskbar   =   0   'False
  17.    Begin VB.CommandButton cmdNoBut 
  18.       Caption         =   "Exit"
  19.       BeginProperty Font 
  20.          Name            =   "MS Serif"
  21.          Size            =   6
  22.          Charset         =   0
  23.          Weight          =   400
  24.          Underline       =   0   'False
  25.          Italic          =   0   'False
  26.          Strikethrough   =   0   'False
  27.       EndProperty
  28.       Height          =   495
  29.       Left            =   120
  30.       TabIndex        =   1
  31.       Top             =   2280
  32.       Width           =   4335
  33.    End
  34.    Begin VB.Timer tmrFollow 
  35.       Enabled         =   0   'False
  36.       Interval        =   1
  37.       Left            =   3480
  38.       Top             =   1800
  39.    End
  40.    Begin VB.CommandButton cmdYesBut 
  41.       Caption         =   "Take the mad cow test"
  42.       BeginProperty Font 
  43.          Name            =   "MS Sans Serif"
  44.          Size            =   9.75
  45.          Charset         =   0
  46.          Weight          =   700
  47.          Underline       =   0   'False
  48.          Italic          =   0   'False
  49.          Strikethrough   =   0   'False
  50.       EndProperty
  51.       Height          =   615
  52.       Left            =   120
  53.       TabIndex        =   0
  54.       Top             =   1560
  55.       Width           =   4335
  56.    End
  57.    Begin VB.Label Label2 
  58.       Alignment       =   2  'Center
  59.       Caption         =   "P.s I dare you to click exit"
  60.       BeginProperty Font 
  61.          Name            =   "MS Sans Serif"
  62.          Size            =   18
  63.          Charset         =   0
  64.          Weight          =   400
  65.          Underline       =   0   'False
  66.          Italic          =   0   'False
  67.          Strikethrough   =   0   'False
  68.       EndProperty
  69.       Height          =   495
  70.       Left            =   120
  71.       TabIndex        =   3
  72.       Top             =   2880
  73.       Width           =   4335
  74.    End
  75.    Begin VB.Label Label1 
  76.       Alignment       =   2  'Center
  77.       Caption         =   "The mad cow test.Have you had yours lately?"
  78.       BeginProperty Font 
  79.          Name            =   "Child's Play"
  80.          Size            =   21.75
  81.          Charset         =   0
  82.          Weight          =   400
  83.          Underline       =   0   'False
  84.          Italic          =   0   'False
  85.          Strikethrough   =   0   'False
  86.       EndProperty
  87.       Height          =   1335
  88.       Left            =   0
  89.       TabIndex        =   2
  90.       Top             =   120
  91.       Width           =   4455
  92.    End
  93. Attribute VB_Name = "frmmain"
  94. Attribute VB_GlobalNameSpace = False
  95. Attribute VB_Creatable = False
  96. Attribute VB_PredeclaredId = True
  97. Attribute VB_Exposed = False
  98. Option Explicit
  99. Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  100.     'Sets the position of the window
  101. Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
  102.     'Set the parent of ANY object (can be lots of fun! ;-)
  103. Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
  104.     'Get the hWnd of the object's parent
  105. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
  106.     'Get the current cursor Hot-Spot position
  107. Private Type POINTAPI
  108.         X As Long
  109.         Y As Long
  110. End Type
  111. Const a_Radius = 30 'Acceptable Radius the cursor can be
  112.                 'within for the button to 'grab' the cursor
  113. Const HWND_TOPMOST = -1
  114. Dim XnY As POINTAPI, ExitDo As Boolean
  115. Private Sub cmdNoBut_Click()
  116.     cmdYesBut.ZOrder 0  'Set the follower button to infront
  117.     tmrFollow.Enabled = True  'Start the button moving!
  118. End Sub
  119. Private Sub cmdYesBut_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  120.     'The Click event doesn't work when the button's parent is set to None
  121.     ExitDo = True
  122.     'Stop the Do..Loop from running, though you don't need
  123.     'this if you're going to unload the form like this
  124.     If GetParent(cmdYesBut.hwnd) <> Me.hwnd Then cmdYesBut.Visible = False
  125.     'If the parent was set to anything other than the form
  126.     'then make it invisible, so it wont get infront of the
  127.     'message box
  128.     start.Show
  129.     Unload frmmain
  130. End Sub
  131. Private Sub tmrFollow_Timer()
  132.     GetCursorPos XnY
  133.     XnY.X = ScaleX(XnY.X, vbPixels, vbTwips) 'Change the dimensions from Pixels
  134.     XnY.Y = ScaleY(XnY.Y, vbPixels, vbTwips) 'to Twips
  135.     'Movement in X
  136.     If cmdYesBut.Left < 0 Then
  137.         cmdYesBut.Left = 0
  138.         Me.Left = Me.Left - 15  'push window
  139.     ElseIf cmdYesBut.Left + cmdYesBut.Width > Me.Width Then
  140.         cmdYesBut.Left = Me.Width - cmdYesBut.Width
  141.         Me.Left = Me.Left + 15  'push window
  142.     Else:
  143.         If cmdYesBut.Left + cmdYesBut.Width / 2 + Me.Left < XnY.X Then cmdYesBut.Left = cmdYesBut.Left + 30 Else cmdYesBut.Left = cmdYesBut.Left - 30
  144.     End If
  145.     'Movement in Y
  146.     If cmdYesBut.Top < 0 Then
  147.         cmdYesBut.Top = 0
  148.         Me.Top = Me.Top - 15
  149.     ElseIf cmdYesBut.Top + cmdYesBut.Height > Me.Height Then
  150.         cmdYesBut.Top = Me.Height - cmdYesBut.Height
  151.         Me.Top = Me.Top + 15
  152.     Else:
  153.         If cmdYesBut.Top + cmdYesBut.Height / 2 + Me.Top < XnY.Y Then cmdYesBut.Top = cmdYesBut.Top + 30 Else cmdYesBut.Top = cmdYesBut.Top - 30
  154.     End If
  155.     If (cmdYesBut.Left + cmdYesBut.Width / 2 + Me.Left < XnY.X + a_Radius) _
  156.         And (cmdYesBut.Left + cmdYesBut.Width / 2 + Me.Left > XnY.X - a_Radius) _
  157.         And (cmdYesBut.Top + cmdYesBut.Height / 2 + Me.Top > XnY.Y - a_Radius) _
  158.         And (cmdYesBut.Top + cmdYesBut.Height / 2 + Me.Top < XnY.Y + a_Radius) Then
  159.         'Within a_Radius twips of the center
  160.         '(pretty long IF statement huh?!)
  161.         tmrFollow.Enabled = False
  162.         Call StickButton(Me, cmdYesBut, cmdYesBut.Width / 2, cmdYesBut.Height / 2)
  163.     End If
  164. End Sub
  165. Private Sub StickButton(ByVal Form As Form, ByVal Button As CommandButton, DpX As Long, DpY As Long)
  166.     SetParent Button.hwnd, 0    'Sets the button's parent to none
  167.     SetWindowPos Button.hwnd, HWND_TOPMOST, 0, 0, 0, 0, 3 'Sets the button to be always on top
  168.     Button.Move Button.Left + Form.Left, Button.Top + Form.Top 'Make sure it's in the same position
  169.     Do
  170.         DoEvents    'So it doesn't 'Hang' the program
  171.         GetCursorPos XnY
  172.         XnY.X = ScaleX(XnY.X, vbPixels, vbTwips)
  173.         XnY.Y = ScaleY(XnY.Y, vbPixels, vbTwips)
  174.         Button.Left = XnY.X - DpX
  175.         Button.Top = XnY.Y - DpY
  176.         If ExitDo Then Exit Do
  177.     Loop  'Stick the Button to the cursor until ExitDo is true
  178.     'And they wont be able to click anything else!! hehe!
  179.     '...why not disable CTRL+ALT+DELETE? hehe!
  180. End Sub
  181.